package com.gaofans.nrpc.client.route;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author GaoFans
 */
public class Service {
    private final String serviceId;
    private final List<ServiceInstance> instances;

    public Service(String serviceId) {
        this.serviceId = Objects.requireNonNull(serviceId);
        instances = new ArrayList<>();
    }

    public String getServiceId() {
        return serviceId;
    }

    public void addInstance(ServiceInstance instance){
        instances.add(instance);
    }

    public List<ServiceInstance> getInstances() {
        return instances;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Service)) return false;
        Service service = (Service) o;
        return getServiceId().equals(service.getServiceId());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getServiceId());
    }
}
